﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SimpleFileDataAndViewModels;

namespace SimpleImageApplication
{
    /// <summary>
    /// Interaction logic for ImageViewer.xaml
    /// </summary>
    public partial class ImageViewer : UserControl
    {
        public static readonly DependencyProperty IImageSourceProviderProperty =
            DependencyProperty.Register("IImageSourceProvider", typeof(IImageSourceProvider), typeof(ImageViewer), new PropertyMetadata(null, OnIImageSourceProviderPropertyChanged));

        public IImageSourceProvider IImageSourceProvider
        {
            get { return (IImageSourceProvider)GetValue(IImageSourceProviderProperty); }
            set { SetValue(IImageSourceProviderProperty, value); }
        }

        private static void OnIImageSourceProviderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ImageViewer source = d as ImageViewer;
            source.UpdateIImageSourceProvider(e.NewValue as IImageSourceProvider, e.OldValue as IImageSourceProvider);
        }

        private void UpdateIImageSourceProvider(IImageSourceProvider viewModel, IImageSourceProvider viewModelOld)
        {
            this.DataContext = viewModel;
        }

        public ImageViewer()
        {
            InitializeComponent();
        }
    }
}
